<?
/******************************************
* ZEMPLATE
* ---------------------------
* A PHP template by Zenyai
* 
* For more information: http://code.google.com/p/zemplate/
* This project is under an open source license (Apache License, Version 2.0)
* http://www.apache.org/licenses/LICENSE-2.0
*
*******************************************/

class LoadDB {
	public $row;

	function __construct($var) {
		include("config.php");
		
		if($var[0] == "pref"){
			$db_selected = $pref_db_name;
		} elseif($var[0] == "house_pt"){
			$db_selected = $house_pt_db_name;
		}
		// Connect to server and select databse.
		mysql_connect("$db_host", "$db_username", "$db_password")or die("Cannot connect to Mysql"); 
		mysql_select_db("$db_name")or die("Cannot select DB");

		if($var[2] == false){
		if(!isset($var[3])){
		$query = "SELECT * FROM $db_selected";
		}elseif(!isset($var[5])){ 
		$query = "SELECT * FROM $db_selected WHERE $var[3]='$var[4]'";
		}
		}elseif($var[2] == true){
		$query = "SELECT COUNT(id) FROM $db_selected WHERE $var[3]='$var[4]' and $var[5]='$var[6]'";
		}
		
		// if set to true then fetch array
		if($var[1] == true){
			$result = mysql_query($query) or die(mysql_error());
			//${"row".$var[0]} = mysql_fetch_array($result);
			$this->row = mysql_fetch_array($result);
		}
	}
	
	// get fetch array value
	function getRow($var) {
		$get = $this->row["$var"];
		return $get;
	}
}
?>